using System;
using Deepcode.Flux.Core.Codons;
using Deepcode.Flux.Core.Extensions;
using Deepcode.Flux.Core.Extensions.Codons;
using Deepcode.Flux.Core.Systems.UI.Menus;

namespace Deepcode.Flux.Core.Codons.Menus
{
	/// <summary>
	///	<MenuItemApp
	///		id="qmprofile" 
	///		href="~/admin/Security/MyProfile/default.aspx" 
	///		caption="My Profile"
	///		persmission="permissioncode"/>
	/// 
	/// Codon representing a menu entry that will navigate the main application window.
	/// 
	/// </summary>
	[XmlCodonName("MenuItemApp")]
	public class MenuItemAppCodon : AbstractPermissionCodon
	{
		[XmlCodonAttribute("href")]
		private string href = "";
		[XmlCodonAttribute("caption")]
		private string caption = "";
			
		public override object BuildItem(object owner, System.Collections.ArrayList subItems)
		{
			if( ! CheckUser()) return null;

			if( owner == null ) 
				throw new Exception("BuildItem failed on MenuItem codon due to owner not being a System.Web.UI.Page");

			System.Web.UI.Page ownerpage = (System.Web.UI.Page) owner;
			MenuApplicationLink link = new MenuApplicationLink(ownerpage, href, caption);
			return link;
		}

	}
}
